package com.ruoyi.lol.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.lol.domain.LolGameRecord;
import com.ruoyi.lol.service.ILolGameRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;


import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 游戏对局记录Controller
 * 
 * @author ruoyi
 * @date 2025-04-20
 */
@RestController
@RequestMapping("/lol/record")
public class LolGameRecordController extends BaseController
{
    @Autowired
    private ILolGameRecordService lolGameRecordService;

    /**
     * 查询游戏对局记录列表
     */
    @PreAuthorize("@ss.hasPermi('lol:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(LolGameRecord lolGameRecord)
    {
        startPage();
        List<LolGameRecord> list = lolGameRecordService.selectLolGameRecordList(lolGameRecord);
        return getDataTable(list);
    }

    /**
     * 导出游戏对局记录列表
     */
    @PreAuthorize("@ss.hasPermi('lol:record:export')")
    @Log(title = "游戏对局记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LolGameRecord lolGameRecord)
    {
        List<LolGameRecord> list = lolGameRecordService.selectLolGameRecordList(lolGameRecord);
        ExcelUtil<LolGameRecord> util = new ExcelUtil<LolGameRecord>(LolGameRecord.class);
        util.exportExcel(response, list, "游戏对局记录数据");
    }

    @Log(title = "导入游戏对局记录", businessType = BusinessType.IMPORT)
    @PostMapping("/importRecord")
    public AjaxResult importRecord(MultipartFile file) throws IOException {
        ExcelUtil<LolGameRecord> util = new ExcelUtil<>(LolGameRecord.class);
        List<LolGameRecord> gameRecordList = util.importExcel(file.getInputStream());
        return lolGameRecordService.importData(gameRecordList);
    }

    /**
     * 获取游戏对局记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('lol:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(lolGameRecordService.selectLolGameRecordById(id));
    }

    /**
     * 新增游戏对局记录
     */
    @PreAuthorize("@ss.hasPermi('lol:record:add')")
    @Log(title = "游戏对局记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LolGameRecord lolGameRecord)
    {
        return toAjax(lolGameRecordService.insertLolGameRecord(lolGameRecord));
    }

    /**
     * 修改游戏对局记录
     */
    @PreAuthorize("@ss.hasPermi('lol:record:edit')")
    @Log(title = "游戏对局记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LolGameRecord lolGameRecord)
    {
        return toAjax(lolGameRecordService.updateLolGameRecord(lolGameRecord));
    }

    /**
     * 删除游戏对局记录
     */
    @PreAuthorize("@ss.hasPermi('lol:record:remove')")
    @Log(title = "游戏对局记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lolGameRecordService.deleteLolGameRecordByIds(ids));
    }
}
